#include "Comm.hpp"
#include <sys/ipc.h>
#include <sys/shm.h>
 #include <fcntl.h>
#include <stdio.h>
#include <cstring>

int main()
{
    key_t key= ftok(FTOK_PATH, PROJ_ID);
    printf("key: %d\n",key);
    int shmid= shmget(key, 4096, IPC_CREAT);

    char* p= (char*)shmat(shmid, nullptr, 0);

    int wfd= open("fifo",O_WRONLY);

    char buf[1024];
    while(1)
    {
        printf("输入你想对服务器说的：");
        fflush(stdout);

        int n= read(0, buf, 1023);
        buf[n-1]= 0;//将\n弄成\0
        if(strcmp(buf,"quit")== 0)
        {
            close(wfd);
            shmdt(p);
            break;
        }

        strcpy(p, buf);
        int tmp=1;
        write(wfd, &tmp, 4);//通知服务器数据已经准备好
    }


    return 0;
}